/**
 * 帐户表服务类实现
 * 周捷
 * 2014-1-6
 */
package com.passkeeper.jdbc.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.passkeeper.jdbc.dao.AccountMapper;
import com.passkeeper.jdbc.model.Account;
import com.passkeeper.jdbc.model.AccountExample;
import com.passkeeper.jdbc.service.inteface.IAccountService;

@Service("accountService")
public class AccountService implements IAccountService{
	
	@Autowired
	private AccountMapper mapper;
	
	/*
	 * (non-Javadoc)
	 * @see com.passkeeper.jdbc.service.inteface.IAccountService#getAccountListByUser(java.lang.String, java.lang.String, java.lang.String)
	 */
	public List<Account> getAccountListByUser(int userid,String type,String name){
		try{
			AccountExample example = new AccountExample();
			AccountExample.Criteria criteria= example.createCriteria();
			if(userid<=0){
				throw new Exception();
			}
			criteria.andUseridEqualTo(userid);
			if(type!=null && !type.equals("")){
				criteria.andTypeEqualTo(type);
			}
			if(name!=null && !name.equals("")){
				criteria.andNameEqualTo("%"+name+"%");
			}
			List<Account> accountList=mapper.selectByExample(example);
			return accountList;
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}
	
	public int insert(Account account){
		return mapper.insert(account);
	}

}
